package com.easyCms.base.service;

import com.easyCms.base.common.CodeConst;
import com.easyCms.base.dao.AppApplyListDAO;
import com.easyCms.base.entity.AppApplyList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AppApplyListSV {
    @Autowired
    private AppApplyListDAO appApplyListDAO;

    public AppApplyList findValidByPhoneNumber(String phoneNumber) {
        return appApplyListDAO.findByPhoneNumberAndState(phoneNumber, CodeConst.State.STATE_VALID);
    }

    public AppApplyList save(AppApplyList appApplyList) {
        return appApplyListDAO.save(appApplyList);
    }

    /**
     * 审核单列表
     *
     * @param pageNumber
     * @param pageSize
     * @return
     */
    public List<AppApplyList> getUserApplyList(int pageNumber, int pageSize) {
        Pageable pageable = new PageRequest(pageNumber - 1, pageSize, Direction.DESC, "id");
        return appApplyListDAO.findByState(CodeConst.State.STATE_VALID, pageable);

    }

    public AppApplyList findValidById(Long applyId) {
        return appApplyListDAO.findByIdAndState(applyId, CodeConst.State.STATE_VALID);
    }
}
